package com.toe.user.webapi.controller;


import com.toe.common.restful.JsonPage;
import com.toe.common.restful.JsonResult;
import com.toe.pojo.dto.user.UserAddressDTO;
import com.toe.pojo.vo.user.UserAddressVO;
import com.toe.user.service.UserAddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 陶涛
 * @since 2022-07-19
 */
@RestController
@RequestMapping("/webapi/user-address")
@Api(tags = "用户地址模块")
public class UserAddressController {

    @Autowired
    private UserAddressService userAddressService;

    @ApiOperation("新增地址")
    @PostMapping("/insert")
    public JsonResult<Void> insert(@RequestBody UserAddressDTO userAddressDTO){
        userAddressService.insert(userAddressDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除地址")
    @PostMapping("/delete")
    public JsonResult<Void> delete(long id){
        userAddressService.deleteById(id);
        return JsonResult.ok();
    }

    @ApiOperation("修改地址")
    @PostMapping("/update/{id}")
    public JsonResult<Void> update(@PathVariable long id, String address){
        userAddressService.updateAddress(id,address);
        return JsonResult.ok();
    }

    @ApiOperation("查询地址")
    @GetMapping("/select")
    public JsonResult<List<UserAddressVO>> selectAllAddress(){
        List<UserAddressVO> userAddressVOS = userAddressService.selectUserAddress();
        return JsonResult.ok(userAddressVOS);
    }

    @ApiOperation("分页查询地址")
    @GetMapping("/select/page")
    public JsonResult<JsonPage<UserAddressVO>> selectAllAddressPage(Integer pageNum,Integer pageSize){
        JsonPage<UserAddressVO> userAddressVOJsonPage = userAddressService.selectUserAddressPage(pageNum, pageSize);
        return JsonResult.ok(userAddressVOJsonPage);
    }
}

